//
//  WPTansStyleAlertView.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/9.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPTansStyleAlertView.h"

@interface WPTansStyleAlertView ()
@property (nonatomic, strong) UILabel * sigeleLabel;/**< 单个转卖 */
@property (nonatomic, strong) UILabel * coupleLabel;/**< 一对转卖 */
@property (nonatomic, strong) UILabel * teamLabel;/**< 组合转卖 */
@property (nonatomic, copy) void (^complete)(NSString *result);/**< 结果block */
- (void)initializeAppearance;/**< 一般界面初始化 */


@end
@implementation WPTansStyleAlertView

+ (WPTansStyleAlertView *)showViewWithSize:(CGRect)rect andWithTitle:(NSString *)title WithComplete:(void (^)(NSString *))complete {
    WPTansStyleAlertView * view = [[WPTansStyleAlertView alloc]initWithTitle:title withSize:rect WithComplete:complete];
    [view show];
    return view;
}

- (instancetype)initWithTitle:(NSString *)title withSize:(CGRect)rect WithComplete:(void (^)(NSString *))complete {
    self = [super initWithFrame:rect withTitle:title];
    if (self) {
        _complete = complete;
        [self initializeAppearance];
    }
    return self;
}
#pragma mark - init
- (void)initializeAppearance {
    [self addSubview:self.sigeleLabel];
    [self addSubview:self.coupleLabel];
    [self addSubview:self.teamLabel];
}
#pragma mark - responds events
- (void)respondsToSigleLabel {
    [self hide];
    _complete(_sigeleLabel.text);
}
- (void)respondsToCoupleLabel {
    [self hide];
    _complete(_coupleLabel.text);
}
- (void)respondsToTeamLabel {
    [self hide];
    _complete(_teamLabel.text);
}
#pragma mark - getter
- (UILabel *)sigeleLabel {
    if (!_sigeleLabel) {
        _sigeleLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 40*DHFlexibleHorizontalMutiplier()+2, CGRectGetMaxX(self.bounds)-20*DHFlexibleHorizontalMutiplier(), 50*DHFlexibleHorizontalMutiplier())];
            UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(lab.bounds)-0.5, CGRectGetMaxX(lab.bounds), 0.5)];
            line.backgroundColor = COLOR_RGB(232, 232, 232, 1);
            [lab addSubview:line];
            UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(respondsToSigleLabel)];
            lab.userInteractionEnabled = YES;
            [lab addGestureRecognizer:tap];
            lab.textColor = COLOR_RGB(61, 61, 61, 1);
            lab.textAlignment = NSTextAlignmentCenter;
            lab.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            lab.text = @"单个转让";
            lab;
        });
    }
    return _sigeleLabel;
}
- (UILabel *)coupleLabel {
    if (!_coupleLabel) {
        _coupleLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.sigeleLabel.frame), CGRectGetMaxX(self.bounds)-20*DHFlexibleHorizontalMutiplier(), 50*DHFlexibleHorizontalMutiplier())];
            UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(lab.bounds)-0.5, CGRectGetMaxX(lab.bounds), 0.5)];
            line.backgroundColor = COLOR_RGB(232, 232, 232, 1);
            [lab addSubview:line];
            UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(respondsToCoupleLabel)];
            lab.userInteractionEnabled = YES;
            [lab addGestureRecognizer:tap];
            lab.textColor = COLOR_RGB(61, 61, 61, 1);
            lab.textAlignment = NSTextAlignmentCenter;
            lab.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            lab.text = @"一对转让";
            lab;
        });
    }
    return _coupleLabel;
}
- (UILabel *)teamLabel {
    if (!_teamLabel) {
        _teamLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.coupleLabel.frame), CGRectGetMaxX(self.bounds)-20*DHFlexibleHorizontalMutiplier(), 50*DHFlexibleHorizontalMutiplier())];
            UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(respondsToTeamLabel)];
            [lab addGestureRecognizer:tap];
            lab.userInteractionEnabled = YES;
            lab.textColor = COLOR_RGB(61, 61, 61, 1);
            lab.textAlignment = NSTextAlignmentCenter;
            lab.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            lab.text = @"两个以上组合转让";
            lab;
        });
    }
    return _teamLabel;
}
@end
